<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('新增填报模板')" />
    <th:block th:include="include :: luckysheet-plugins-css" />
</head>

<body class="white-bg">
    <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height:100%;left: 0px;top: 0px;"></div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: luckysheet-plugins-js" />
    <script th:inline="javascript">
        var prefix = ctx + "work/template"
        var template = [[${ workTemplate }]]
        var defaultData = [{
            "name": "Sheet1",
            "color": "",
            "index": 1,
            "status": 0,
            "order": 1,
            "celldata": [],
            "data": [],
            "config": {}
        },]

        function submitHandler() {
            template['templateContent'] = JSON.stringify(luckysheet.getAllSheets())
            var config = {
                url: prefix + "/edit",
                type: "post",
                dataType: "json",
                data: template,
                success: function (result) {
                    if (typeof callback == "function") {
                        callback(result);
                    }
                    layer.msg(result.msg)
                },
                error: function (result) {
                    layer.msg(result.msg)
                }
            }
            $.ajax(config)
        }

        $(function () {
            luckysheet.create({
                container: 'luckysheet',
                title: template.templateName,
                lang: 'zh',
                showinfobar: true,
                showtoolbar: true,
                sheetFormulaBar: false,
                myFolderUrl: ctx + 'work/template',
                functionButton: '<button onclick="submitHandler()" type="button" class="btn btn-primary"><i class="fa fa-check"></i>保 存</button>',
                data: undefined === template.templateContent || '' === template.templateContent ? defaultData : JSON.parse(template.templateContent),
                row: 18,
                column: 16,
            })
        })
    </script>
</body>

</html>